/**
 * Created with IntelliJ IDEA.
 * Description:删除重复项（返回新长度）
 * User: xwl
 * Date: 2023-05-07
 * Time: 23:34
 */
public class Test3 {
    // 借鉴
        public int removeDuplicates(int[] nums) {
            int n = nums.length;
            if (n == 0) {
                return 0;
            }
            // 快指针，用来遍历数组
            int fast = 1;
            // 慢指针，用来标记插入位置
            int slow = 1;
            while (fast < n) {
                if (nums[fast] != nums[fast - 1]) {
                    nums[slow] = nums[fast];
                    ++slow;
                }
                ++fast;
            }
            return slow;
        }
}
